package com.iknow.xmpp.service;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import com.iknow.xmpp.util.PresenceAdapter;
import com.iknow.xmpp.util.Status;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;

public class Contact
  implements Parcelable
{
  public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator()
  {
    public Contact createFromParcel()
    {
      return new Contact(paramParcel, null);
    }

    public Contact[] newArray()
    {
      return new Contact[paramInt];
    }
  };
  private String mAvatarId;
  private final List<String> mGroups = new ArrayList();
  private int mID;
  private final String mJID;
  private String mMsgState;
  private String mName;
  private List<String> mRes;
  private String mSelectedRes;
  private int mStatus;

  public Contact(Uri paramUri)
  {
    if (!("xmpp".equals(paramUri.getScheme())))
      throw new IllegalArgumentException();
    String str1 = paramUri.getEncodedSchemeSpecificPart();
    this.mJID = StringUtils.parseBareAddress(str1);
    this.mName = this.mJID;
    this.mStatus = 100;
    this.mMsgState = null;
    this.mRes = new ArrayList();
    String str2 = StringUtils.parseResource(str1);
    this.mSelectedRes = str2;
    this.mRes.add(str2);
  }

  private Contact(Parcel paramParcel)
  {
    this.mID = paramParcel.readInt();
    this.mStatus = paramParcel.readInt();
    this.mJID = paramParcel.readString();
    this.mSelectedRes = paramParcel.readString();
    this.mName = paramParcel.readString();
    this.mMsgState = paramParcel.readString();
    this.mAvatarId = paramParcel.readString();
    this.mRes = new ArrayList();
    paramParcel.readStringList(this.mRes);
    paramParcel.readStringList(this.mGroups);
  }

  public Contact(String paramString)
  {
    this.mJID = StringUtils.parseBareAddress(paramString);
    this.mName = this.mJID;
    this.mStatus = 100;
    this.mMsgState = null;
    this.mRes = new ArrayList();
    String str = StringUtils.parseResource(paramString);
    this.mSelectedRes = str;
    if (!("".equals(str)))
      this.mRes.add(str);
  }

  public static Uri makeXmppUri(String paramString)
  {
    StringBuilder localStringBuilder = new StringBuilder("xmpp:");
    String str1 = StringUtils.parseName(paramString);
    localStringBuilder.append(str1);
    if (!("".equals(str1)))
      localStringBuilder.append('@');
    localStringBuilder.append(StringUtils.parseServer(paramString));
    String str2 = StringUtils.parseResource(paramString);
    if (!("".equals(str2)))
    {
      localStringBuilder.append('/');
      localStringBuilder.append(str2);
    }
    return Uri.parse(localStringBuilder.toString());
  }

  public void addGroup(String paramString)
  {
    if (!(this.mGroups.contains(paramString)))
      this.mGroups.add(paramString);
  }

  public void addRes(String paramString)
  {
    if (!(this.mRes.contains(paramString)))
      this.mRes.add(paramString);
  }

  public void delGroup(String paramString)
  {
    this.mGroups.remove(paramString);
  }

  public void delRes(String paramString)
  {
    this.mRes.remove(paramString);
  }

  public int describeContents()
  {
    return 0;
  }

  public boolean equals(Object paramObject)
  {
    boolean bool;
    if (!(paramObject instanceof Contact))
      bool = false;
    while (true)
    {
      while (true)
      {
        return bool;
        if (paramObject != this)
          break;
        bool = true;
      }
      bool = ((Contact)paramObject).getJID().equals(getJID());
    }
  }

  public String getAvatarId()
  {
    return this.mAvatarId;
  }

  public List<String> getGroups()
  {
    return this.mGroups;
  }

  public int getID()
  {
    return this.mID;
  }

  public String getJID()
  {
    return this.mJID;
  }

  public String getJIDWithRes()
  {
    StringBuilder localStringBuilder = new StringBuilder(this.mJID);
    if (!("".equals(this.mSelectedRes)))
      localStringBuilder.append('/').append(this.mSelectedRes);
    return localStringBuilder.toString();
  }

  public List<String> getMRes()
  {
    return this.mRes;
  }

  public String getMsgState()
  {
    return this.mMsgState;
  }

  public String getName()
  {
    return this.mName;
  }

  public String getSelectedRes()
  {
    return this.mSelectedRes;
  }

  public int getStatus()
  {
    return this.mStatus;
  }

  public int hashCode()
  {
    return this.mJID.hashCode();
  }

  public void setAvatarId(String paramString)
  {
    this.mAvatarId = paramString;
  }

  public void setGroups(Collection<RosterGroup> paramCollection)
  {
    this.mGroups.clear();
    Iterator localIterator = paramCollection.iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
        return;
      RosterGroup localRosterGroup = (RosterGroup)localIterator.next();
      this.mGroups.add(localRosterGroup.getName());
    }
  }

  public void setGroups(List<String> paramList)
  {
    this.mGroups.clear();
    this.mGroups.addAll(paramList);
  }

  public void setID(int paramInt)
  {
    this.mID = paramInt;
  }

  public void setMRes(List<String> paramList)
  {
    this.mRes = paramList;
  }

  public void setMsgState(String paramString)
  {
    this.mMsgState = paramString;
  }

  public void setName(String paramString)
  {
    if ((paramString == null) || ("".equals(paramString)))
    {
      this.mName = this.mJID;
      this.mName = StringUtils.parseName(this.mName);
      if ((this.mName == null) || ("".equals(this.mName)))
        this.mName = this.mJID;
    }
    while (true)
    {
      return;
      this.mName = paramString;
    }
  }

  public void setSelectedRes(String paramString)
  {
    this.mSelectedRes = paramString;
  }

  public void setStatus(int paramInt)
  {
    this.mStatus = paramInt;
  }

  public void setStatus(PresenceAdapter paramPresenceAdapter)
  {
    this.mStatus = paramPresenceAdapter.getStatus();
    this.mMsgState = paramPresenceAdapter.getStatusText();
  }

  public void setStatus(Presence paramPresence)
  {
    this.mStatus = Status.getStatusFromPresence(paramPresence);
    this.mMsgState = paramPresence.getStatus();
  }

  public String toString()
  {
    String str;
    if (this.mJID != null)
      str = this.mJID + "/[" + this.mRes + "]";
    while (true)
    {
      return str;
      str = super.toString();
    }
  }

  public Uri toUri()
  {
    return makeXmppUri(this.mJID);
  }

  public Uri toUri(String paramString)
  {
    StringBuilder localStringBuilder = new StringBuilder("xmpp:");
    String str = StringUtils.parseName(this.mJID);
    localStringBuilder.append(str);
    if (!("".equals(str)))
      localStringBuilder.append('@');
    localStringBuilder.append(StringUtils.parseServer(this.mJID));
    if (!("".equals(paramString)))
    {
      localStringBuilder.append('/');
      localStringBuilder.append(paramString);
    }
    return Uri.parse(localStringBuilder.toString());
  }

  public void writeToParcel(Parcel paramParcel, int paramInt)
  {
    paramParcel.writeInt(this.mID);
    paramParcel.writeInt(this.mStatus);
    paramParcel.writeString(this.mJID);
    paramParcel.writeString(this.mSelectedRes);
    paramParcel.writeString(this.mName);
    paramParcel.writeString(this.mMsgState);
    paramParcel.writeString(this.mAvatarId);
    paramParcel.writeStringList(getMRes());
    paramParcel.writeStringList(getGroups());
  }
}